﻿<%@ WebHandler Language="C#" Class="BathResMonitorMaintHandler" %>

/*Description: 槽液化验设备检测项维护处理程序
'Copyright (c) : 通力凯顿（北京）系统集成有限公司
'Writer: Zhangrj 
'create Date:20221121
'Rewriter:
'Rewrite Date:
*/
using System;
using System.Web;
using BusinessRule.DTO;
using System.Web.SessionState;
using DatabaseAccess.DBUtility;
using System.Data.OracleClient;
using System.Data;
using Newtonsoft.Json;
using System.Collections.Generic;
using BusinessRule.Business;
using BusinessRule.IBusiness;
using BusinessRule.BusinessFactory;
using System.IO;
using System.Collections;

public class BathResMonitorMaintHandler : IHttpHandler, IRequiresSessionState
{
    string fileBasePath = "/InSiteWebApplication/Temp2/BathResCheck/";
    CurrentUserInfo m_UserInfo;
    uLMSCommonBusiness commonBusiness = new uLMSCommonBusiness();
    uLMSBathResMonitorBusiness bathResMonitorBusiness = new uLMSBathResMonitorBusiness();
    public void ProcessRequest(HttpContext context)
    {
        try
        {
            m_UserInfo = (CurrentUserInfo)context.Session["CurrentUserInfo"];
            if (m_UserInfo == null)
            {
                context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "数据过期，请重新登录" }));
                return;
            }
            var action = context.Request["action"].ToString();
            switch (action)
            {
                case "GetBathResMonitorList": //获取槽液化验设备检测列表
                    GetBathResMonitorList(context);
                    break;
                case "GetBathResMonitorCheckListByMainID": //获取槽液化验设备检测详细列表（通过主ID）
                    GetBathResMonitorCheckListByMainID(context);
                    break;
                case "GetBathResMonitorCheckList": //获取槽液化验设备送检详细数据列表（预警列表主数据）
                    GetBathResMonitorCheckList(context);
                    break;
                case "GetWindowInitData"://获取弹窗初始化数据
                    GetWindowInitData(context);
                    break;
                case "GetResourceByCode"://获取设备列表（通过工作中心）
                    GetResourceByCode(context);
                    break;
                case "SaveBathResMonitorData"://保存槽液化验设备检测项数据
                    SaveBathResMonitorData(context);
                    break;
                case "CreateCheckBill"://保存槽液化验设备送检明细（生成送检化验单）
                    CreateCheckBill(context);
                    break;
                case "UpdateBathResMonitorStatus"://更新槽液化验设备检测项状态
                    UpdateBathResMonitorStatus(context);
                    break;
                case "UpdateBathResMonitorCheckStatus"://更新槽液化验设备送检明细状态
                    UpdateBathResMonitorCheckStatus(context);
                    break;
                case "UploadCheckFile"://保存送检报告
                    UploadCheckFile(context);
                    break;
                default:
                    break;
            }
        }
        catch (Exception ex)
        {
            var result = new uMESProcessResult();
            result.Result = false;
            result.Message = ex.Message;
            context.Response.ContentType = "text/html";
            context.Response.Write(JsonConvert.SerializeObject(result));
        }
    }

    public void UploadCheckFile(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Message = "上传成功", Result = true };
        string fpath = string.Empty;
        try
        {
            if (!Directory.Exists(context.Server.MapPath(fileBasePath)))
            {
                Directory.CreateDirectory(context.Server.MapPath(fileBasePath));
            }
            string bathResmonitorCheckID = context.Request["bathResmonitorCheckID"].ToString();
            if (string.IsNullOrWhiteSpace(bathResmonitorCheckID))
            {
                result.Result = false;
                result.Message = "未选择送检单";
            }
            if (result.Result)
            {
                var files = context.Request.Files;
                var file = files.Count > 1 ? files[files.Count - 1] : files[0];
                string IsXls = Path.GetExtension(file.FileName);
                string fileName = Path.GetFileNameWithoutExtension(file.FileName) + DateTime.Now.ToString("yyyyMMddHHmmssffff") + IsXls;
                fpath = context.Server.MapPath(fileBasePath + fileName);
                file.SaveAs(fpath);//保存文件
                //更新送检明细数据库
                ExcuteEntity exuteEntity = new ExcuteEntity("bathresmonitorcheck", ExcuteEntity.ExcuteTypeEnum.update);
                exuteEntity.WhereFileds = new List<FieldEntity>() { new FieldEntity("bathResmonitorCheckID", bathResmonitorCheckID, FieldEntity.FieldTypeEnum.Str) };
                List<FieldEntity> excuteFieldList = new List<FieldEntity>();
                excuteFieldList.Add(new FieldEntity("checkdocpath", "/Temp2/BathResCheck/" + fileName, FieldEntity.FieldTypeEnum.Str));
                exuteEntity.ExcuteFileds = excuteFieldList;
                result.Result = DatabaseHelper.ExecuteDataByEntity(exuteEntity);
                if (!result.Result)
                {
                    DeleteFile(fpath);
                    result.Message = "上传失败";
                }
            }
            context.Response.Write(JsonConvert.SerializeObject(result));
        }
        catch (Exception e)
        {
            DeleteFile(fpath);
            result.Result = false;
            result.Message = "上传失败：" + e.Message;
            context.Response.Write(JsonConvert.SerializeObject(result));
        }
    }

    /// <summary>
    /// 删除文件
    /// </summary>
    /// <param name="fpath">文件地址</param>
    private void DeleteFile(string fpath)
    {
        if (File.Exists(fpath))
        {
            new FileInfo(fpath).Attributes = FileAttributes.Normal;
            File.Delete(fpath);
        }
    }

    /// <summary>
    /// 获取槽液化验设备检测维护数据
    /// </summary>
    /// <param name="context"></param>
    public void GetBathResMonitorList(HttpContext context)
    {
        Dictionary<string, string> para = new Dictionary<string, string>();
        para.Add("PageNumber", context.Request["pageIndex"].ToString());
        para.Add("PageSize", context.Request["pageSize"].ToString());
        para.Add("WorkCenterCode", context.Request["workcentercode"].ToString());
        para.Add("Resource", context.Request["resource"].ToString());
        para.Add("Status", context.Request["status"].ToString());
        para.Add("IsEnable", context.Request["isEnable"].ToString());
        para.Add("FactoryID", context.Request["factory"].ToString());
        uMESProcessResult result = bathResMonitorBusiness.GetBathResMonitorListByPage(para);
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 获取槽液化验设备检测详细数据（通过检测主ID）
    /// </summary>
    /// <param name="context"></param>
    public void GetBathResMonitorCheckListByMainID(HttpContext context)
    {
        uMESPagingDataDTO pager = new uMESPagingDataDTO();
        string strSql = "select * from bathresmonitorcheck b WHERE b.bathresmonitorinfoid = '" + context.Request["bathID"].ToString() + "' AND b.isuse = '0'";
        pager.CurrentPageIndex = Convert.ToInt32(context.Request["pageIndex"].ToString());
        pager.PageSize = Convert.ToInt32(context.Request["pageSize"].ToString());
        pager.strSQL = strSql;
        uMESProcessResult result = DatabaseHelper.RunProcedureForPage(pager);
        foreach (DataRow item in result.DBTable.Rows)
        {
            if (!string.IsNullOrWhiteSpace(item["CHECKDOCPATH"].ToString()))
            {
                item["CHECKDOCPATH"] = Path.GetFileName(item["CHECKDOCPATH"].ToString());
            }
        }
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 获取槽液化验设备送检详细数据列表
    /// </summary>
    /// <param name="context"></param>
    public void GetBathResMonitorCheckList(HttpContext context)
    {
        Dictionary<string, string> para = new Dictionary<string, string>();
        para.Add("FactoryID", m_UserInfo.FactoryID);
        para.Add("PageNumber", context.Request["pageIndex"].ToString());
        para.Add("PageSize", context.Request["pageSize"].ToString());
        para.Add("WorkCenterCode", context.Request["workcentercode"].ToString());
        para.Add("Resource", context.Request["resource"].ToString());
        para.Add("Status", context.Request["status"].ToString());
        para.Add("SendCheckDate", context.Request["sendCheckDate"].ToString());
        para.Add("ChangeDate", context.Request["changeDate"].ToString());
        para.Add("OverdueStatus", context.Request["overduestatus"].ToString());
        uMESProcessResult result = bathResMonitorBusiness.GetBathResMonitorCheckListByPage(para);
        foreach (DataRow item in result.DBTable.Rows)
        {
            if (!string.IsNullOrWhiteSpace(item["CHECKDOCPATH"].ToString()))
            {
                item["checkdocFileName"] = Path.GetFileName(item["CHECKDOCPATH"].ToString());
                item["CHECKDOCPATH"] = "http://" + context.Request.Url.Host + context.Request.ApplicationPath + item["CHECKDOCPATH"].ToString();
            }
            else
            {
                item["checkdocFileName"] = "";
            }
        }
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 计算两个日期相隔天数
    /// </summary>
    /// <param name="time1"></param>
    /// <param name="time2"></param>
    /// <returns></returns>
    private int GetDateDiffDays(DateTime time)
    {
        TimeSpan ts1 = new TimeSpan(time.Ticks);
        TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks);
        TimeSpan ts = ts1.Subtract(ts2);
        return ts.TotalDays < 0 ? -1 : ts.Days;
    }
    /// <summary>
    /// 获取弹窗数据
    /// </summary>
    /// <param name="context"></param>
    public void GetWindowInitData(HttpContext context)
    {
        ExcuteEntity exuteEntity = new ExcuteEntity("resourcedef", ExcuteEntity.ExcuteTypeEnum.selectAll);
        exuteEntity.WhereFileds = new List<FieldEntity>() { new FieldEntity("factoryid", m_UserInfo.FactoryID, FieldEntity.FieldTypeEnum.Str) };
        DataTable dtResource = DatabaseHelper.QueryDataByEntity(exuteEntity);
        dtResource.TableName = "dtResource";
        //获取有效的工作中心
        DataTable dtworkcentercode = dtResource.DefaultView.ToTable(true, "workcentercode");
        if (dtworkcentercode.Rows.Count > 0)
        {
            DataRow[] drs = dtworkcentercode.Select("workcentercode is not null");
            if (drs.Length > 0)
            {
                dtworkcentercode = drs.CopyToDataTable();
            }
        }
        dtworkcentercode.TableName = "dtworkcentercode";
        //
        uMESProcessResult result = new uMESProcessResult() { Result = true };
        result.DBDataSet.Tables.Add(dtworkcentercode);
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 通过工作中心获取设备列表
    /// </summary>
    /// <param name="context"></param>
    public void GetResourceByCode(HttpContext context)
    {
        ExcuteEntity exuteEntity = new ExcuteEntity("resourcedef", ExcuteEntity.ExcuteTypeEnum.selectAll);
        exuteEntity.WhereFileds = new List<FieldEntity>() { new FieldEntity("factoryid", m_UserInfo.FactoryID, FieldEntity.FieldTypeEnum.Str),
                                                            new FieldEntity("workcentercode", context.Request["workCenterCode"].ToString(), FieldEntity.FieldTypeEnum.Str)};
        List<FieldEntity> excuteFieldList = new List<FieldEntity>();
        excuteFieldList.Add(new FieldEntity("resourceid", "", FieldEntity.FieldTypeEnum.Str));
        excuteFieldList.Add(new FieldEntity("description", "", FieldEntity.FieldTypeEnum.Str));
        exuteEntity.ExcuteFileds = excuteFieldList;
        DataTable dtResource = DatabaseHelper.QueryDataByEntity(exuteEntity);
        //
        uMESProcessResult result = new uMESProcessResult() { Result = true, DBTable = dtResource };
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    /// <summary>
    /// 保存槽液化验设备检测数据
    /// </summary>
    /// <param name="context"></param>
    public void SaveBathResMonitorData(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Result = true };
        string ressourceDesc = context.Request["ResourceDesc"].ToString();//设备名称
        string resourceId = context.Request["ResourceId"].ToString();//设备ID
        if (ressourceDesc == resourceId)
        {
            result.Result = false;
            result.Message = "设备无效";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }
        string bathresmonitorinfoId = context.Request["Bathresmonitorinfoid"].ToString();//主ID
        string resWorkCenterCode = context.Request["Resworkcentercode"].ToString();//工作中心
        string checkCycle = context.Request["Checkcycle"].ToString();//周期
        DateTime expireDate = DateTime.Parse(context.Request["Expiredate"].ToString() + " 23:59:59");//到期日期
        string description = context.Request["Description"].ToString();//描述
        if (string.IsNullOrWhiteSpace(bathresmonitorinfoId))
        {
            //插入数据库
            ExcuteEntity exuteEntity = new ExcuteEntity("bathResMonitorInfo", ExcuteEntity.ExcuteTypeEnum.insert);
            List<FieldEntity> excuteFieldList = new List<FieldEntity>();
            excuteFieldList.Add(new FieldEntity("Bathresmonitorinfoid", Guid.NewGuid().ToString(), FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Resworkcentercode", resWorkCenterCode, FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Resourceid", resourceId, FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Ressourcedesc", ressourceDesc, FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Checkcycle", checkCycle, FieldEntity.FieldTypeEnum.Numer));
            excuteFieldList.Add(new FieldEntity("Expiredate", expireDate, FieldEntity.FieldTypeEnum.DateTime));
            excuteFieldList.Add(new FieldEntity("Description", description, FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Createemployeeid", m_UserInfo.EmployeeID, FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Createdate", DateTime.Now, FieldEntity.FieldTypeEnum.DateTime));
            excuteFieldList.Add(new FieldEntity("Createempname", m_UserInfo.FullName, FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Isuse", "0", FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("IsEnable", "1", FieldEntity.FieldTypeEnum.Str));
            exuteEntity.ExcuteFileds = excuteFieldList;
            result.Result = DatabaseHelper.ExecuteDataByEntity(exuteEntity);
        }
        else
        {
            //更新数据库
            ExcuteEntity exuteEntity = new ExcuteEntity("bathResMonitorInfo", ExcuteEntity.ExcuteTypeEnum.update);
            exuteEntity.WhereFileds = new List<FieldEntity>() { new FieldEntity("Bathresmonitorinfoid", bathresmonitorinfoId, FieldEntity.FieldTypeEnum.Str) };
            List<FieldEntity> excuteFieldList = new List<FieldEntity>();
            //excuteFieldList.Add(new FieldEntity("Resworkcentercode", resWorkCenterCode, FieldEntity.FieldTypeEnum.Str));
            //excuteFieldList.Add(new FieldEntity("Resourceid", resourceId, FieldEntity.FieldTypeEnum.Str));
            //excuteFieldList.Add(new FieldEntity("Ressourcedesc", ressourceDesc, FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Checkcycle", checkCycle, FieldEntity.FieldTypeEnum.Numer));
            excuteFieldList.Add(new FieldEntity("Expiredate", expireDate, FieldEntity.FieldTypeEnum.DateTime));
            excuteFieldList.Add(new FieldEntity("Description", description, FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Lastchangeempid", m_UserInfo.EmployeeID, FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Lastchangedate", DateTime.Now, FieldEntity.FieldTypeEnum.DateTime));
            excuteFieldList.Add(new FieldEntity("Lastchangeempname", m_UserInfo.FullName, FieldEntity.FieldTypeEnum.Str));
            exuteEntity.ExcuteFileds = excuteFieldList;
            result.Result = DatabaseHelper.ExecuteDataByEntity(exuteEntity);
        }
        result.Message = result.Result ? "保存成功" : "保存失败";
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    /// <summary>
    /// 更新槽液化验设备检测项暂停、删除等状态
    /// </summary>
    /// <param name="context"></param>
    public void UpdateBathResMonitorStatus(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Result = true };
        DataTable paramDt = JsonConvert.DeserializeObject<DataTable>(context.Request["paramDt"].ToString());
        string operaType = context.Request["operaType"].ToString();//操作类型
        string bathresmonitorinfoIDs = "";
        string strSql = "";
        string strQuerySql = "";
        if (operaType == "1")//删除
        {
            strQuerySql = @"SELECT 1 FROM bathresmonitorcheck b WHERE b.bathresmonitorinfoid IN ({0}) AND b.isuse = 0";
            strSql = @"update bathResMonitorInfo b set b.Isuse='1',b.lastchangeempid='{0}',b.lastchangeempname='{1}',b.lastchangedate=SYSDATE where b.Bathresmonitorinfoid in ({2})";
        }
        else if (operaType == "2")//启用/暂停
        {
            strSql = "update bathResMonitorInfo b set b.isenable=DECODE(b.isenable,1,0,1),b.lastchangeempid='{0}',b.lastchangeempname='{1}',b.lastchangedate=SYSDATE where b.Bathresmonitorinfoid in ({2})";
        }
        else
        {
            result.Result = false;
            result.Message = "未知操作类型";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }
        //更新数据库
        foreach (DataRow item in paramDt.Rows)
        {
            bathresmonitorinfoIDs += "'" + item["BathresmonitorinfoID"].ToString() + "',";
        }
        bathresmonitorinfoIDs = bathresmonitorinfoIDs.TrimEnd(',');
        if (strQuerySql != "")
        {
            strQuerySql = string.Format(strQuerySql, bathresmonitorinfoIDs);
            if (DatabaseHelper.GetSingle(strQuerySql) != null)
            {
                result.Result = false;
                result.Message = "存在送检记录，不可删除";
                context.Response.Write(JsonConvert.SerializeObject(result));
                return;
            }
        }
        strSql = string.Format(strSql, m_UserInfo.EmployeeID.ToString(), m_UserInfo.FullName, bathresmonitorinfoIDs);
        DatabaseHelper.ExecuteSql(strSql);
        result.Message = result.Result ? "保存成功" : "保存失败";
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    /// <summary>
    /// 生成化验单
    /// </summary>
    /// <param name="context"></param>
    public void CreateCheckBill(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Result = true };
        DataTable paramDt = JsonConvert.DeserializeObject<DataTable>(context.Request["paramsDt"].ToString());
        DataTable mainDt = paramDt.DefaultView.ToTable(true, "bathresmonitorinfoid");//按照主数据ID去重
        List<ExcuteEntity> list = new List<ExcuteEntity>();
        //计算送检单号
        string seleSql = @"SELECT * FROM(
            SELECT b.bathresmonitorcheckno FROM bathresmonitorcheck b 
            WHERE b.isuse = 0 ORDER BY b.Createdate DESC,b.bathresmonitorcheckno DESC) WHERE ROWNUM =1";
        DataTable dt = DatabaseHelper.Query_ReturnDatTable(seleSql);
        string checkNo = "YPCY" + DateTime.Now.ToString("yyyyMM") + "_";
        int checkNo_num = 1;//默认为1
        if (dt.Rows.Count > 0)
        {
            if (dt.Rows[0]["bathresmonitorcheckno"].ToString().Contains(checkNo))
            {
                checkNo_num = int.Parse(dt.Rows[0]["bathresmonitorcheckno"].ToString().Replace(checkNo, "")) + 1;
            }
        }
        foreach (DataRow item in mainDt.Rows)
        {
            if (DatabaseHelper.GetSingle(string.Format("SELECT 1 FROM bathresmonitorcheck b WHERE b.bathresmonitorinfoid = '{0}' AND b.status = '0' AND b.isuse = 0", item["bathresmonitorinfoid"].ToString())) != null)
            {
                result.Result = false;
                result.Message = "存在送检中的检测单";
                break;
            }
            if (DatabaseHelper.GetSingle(string.Format("SELECT 1 FROM bathresmonitorinfo b WHERE b.bathresmonitorinfoid = '{0}' AND (b.isenable=0 OR b.isuse = 1)", item["bathresmonitorinfoid"].ToString())) != null)
            {
                result.Result = false;
                result.Message = "检测设备已删除或暂停";
                break;
            }
            string lastCheckNo = checkNo + checkNo_num.ToString().PadLeft(4, '0');
            //插入送检明细数据库
            ExcuteEntity exuteEntity = new ExcuteEntity("bathresmonitorcheck", ExcuteEntity.ExcuteTypeEnum.insert);
            List<FieldEntity> excuteFieldList = new List<FieldEntity>();
            excuteFieldList.Add(new FieldEntity("bathresmonitorcheckid", Guid.NewGuid().ToString(), FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Bathresmonitorinfoid", item["bathresmonitorinfoid"].ToString(), FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("bathresmonitorcheckno", lastCheckNo, FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("sendcheckdate", DateTime.Now, FieldEntity.FieldTypeEnum.DateTime));
            excuteFieldList.Add(new FieldEntity("status", "0", FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("sendcheckempid", m_UserInfo.EmployeeID, FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("sendcheckempname", m_UserInfo.FullName, FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Createemployeeid", m_UserInfo.EmployeeID, FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Createdate", DateTime.Now, FieldEntity.FieldTypeEnum.DateTime));
            excuteFieldList.Add(new FieldEntity("Createempname", m_UserInfo.FullName, FieldEntity.FieldTypeEnum.Str));
            excuteFieldList.Add(new FieldEntity("Isuse", "0", FieldEntity.FieldTypeEnum.Str));
            exuteEntity.ExcuteFileds = excuteFieldList;
            list.Add(exuteEntity);
            checkNo_num++;//送检序号自增
        }
        if (result.Result)
        {
            result.Result = DatabaseHelper.ExecuteDataByEntitys(list);
            result.Message = result.Result ? "保存成功" : "保存失败";
        }
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    /// <summary>
    /// 更新槽液化验设备送检明细的删除、完成状态
    /// </summary>
    /// <param name="context"></param>
    public void UpdateBathResMonitorCheckStatus(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Result = true, Message = "保存成功" };
        DataTable paramDt = JsonConvert.DeserializeObject<DataTable>(context.Request["paramsDt"].ToString());
        string operaType = context.Request["operaType"].ToString();//操作类型
        ArrayList list = new ArrayList();
        if (operaType != "1" && operaType != "2")
        {
            result.Result = false;
            result.Message = "未知操作类型";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }
        //更新数据库
        foreach (DataRow item in paramDt.Rows)
        {
            if (item["status"].ToString() == "5")
            {
                result.Result = false;
                result.Message = "存在检验完成的送检单";
                break;
            }
            if (DatabaseHelper.GetSingle(string.Format("SELECT 1 FROM bathresmonitorinfo b WHERE b.bathresmonitorinfoid = '{0}' AND (b.isenable=0 OR b.isuse = 1)", item["bathresmonitorinfoid"].ToString())) != null)
            {
                result.Result = false;
                result.Message = "检测设备已删除或暂停";
                break;
            }
            if (operaType == "2") //送检完成
            {
                //更新送检单状态为完成
                list.Add(string.Format("update bathresmonitorcheck b set b.status='5',b.lastchangeempid='{0}',b.lastchangeempname='{1}',b.lastchangedate=SYSDATE where b.bathresmonitorcheckid = '{2}'", m_UserInfo.EmployeeID.ToString(), m_UserInfo.FullName, item["bathresmonitorcheckid"].ToString()));
                //更新主数据的到期时间
                list.Add(string.Format("update bathResMonitorInfo b set b.expiredate = to_date('{0} 23:59:59','yyyy-MM-dd HH24:mi:ss') + b.checkcycle,b.lastchangeempid='{1}',b.lastchangeempname='{2}',b.lastchangedate=SYSDATE where b.Bathresmonitorinfoid = '{3}'", DateTime.Now.ToString("yyyy-MM-dd"), m_UserInfo.EmployeeID.ToString(), m_UserInfo.FullName, item["Bathresmonitorinfoid"].ToString()));
            }
            else
            {
                //删除送检单
                list.Add(string.Format("update bathresmonitorcheck b set b.Isuse='1',b.lastchangeempid='{0}',b.lastchangeempname='{1}',b.lastchangedate=SYSDATE where b.bathresmonitorcheckid = '{2}'", m_UserInfo.EmployeeID.ToString(), m_UserInfo.FullName, item["bathresmonitorcheckid"].ToString()));
            }
        }
        if (result.Result)
        {
            DatabaseHelper.ExecuteSqlTran(list);
        }
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}